package com.chuangke.mds.dao.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chuangke.mds.dao.mapper.provider.TechnologySimSqlProvider;
import com.chuangke.mds.entity.MdsSimulateReport;
import com.chuangke.mds.entity.TechnologyProcessProcedureNodeSimulate;

@Mapper
public interface TechnologyProcessProcedureNodeSimulateMapper extends BaseMapper<TechnologyProcessProcedureNodeSimulate> {
    @SelectProvider(type = TechnologySimSqlProvider.class, method = "getPage")
    IPage<TechnologyProcessProcedureNodeSimulate> getPage(IPage<TechnologyProcessProcedureNodeSimulate> page, @Param("processId") String processId, @Param("processName") String processName, @Param("procedureName") String procedureName,
                                                          @Param("productMx") String productMx, @Param("status")String status, @Param("start") String start, @Param("end") String end,@Param("userDeptId") String userDeptId);

    @Select("select\n" +
            "\ta.*,\n" +
            "\tb.name process_name,\n" +
            "\td.name product_name,\n" +
            "\tc.name procedure_name,\n" +
            "\te.name dept_name,\n" +
            "\tf.ext_str01 product_mx,b.material_id material_id\n" +
            "\tfrom\n" +
            "\tmds_technology_process_procedure_node_simulate a\n" +
            "\tleft join mds_technology_process b on a.process_id = b.id\n" +
            "\tleft join mds_technology_process_procedure c on a.process_id = c.process_id and a.procedure_id = c.id \n" +
            "\tleft join mds_product d on b.product_id = d.id\n" +
            "\tleft join sys_dept e on b.dept_id = e.id\n" +
            "\tleft join sys_dict f on c.type = f.code AND f.type = 'mds_product_mx_type'\n" +
            "\twhere a.id = #{id}  ")
    TechnologyProcessProcedureNodeSimulate loadInfoById(@Param("id") String id);
    @Select("select\n" +
            "\tb.name process_name,\n" +
            "\td.name product_name,\n" +
            "\tc.name procedure_name,\n" +
            "\te.name dept_name,\n" +
            "\tf.ext_str01 product_mx,b.material_id material_id \n" +
            "from\n" +
            " mds_technology_process b \n" +
            "left join mds_technology_process_procedure c on\n" +
            "\tb.id = c.process_id\n" +
            "left join mds_product d on\n" +
            "\tb.product_id = d.id\n" +
            "left join sys_dept e on\n" +
            "\tb.dept_id = e.id\n" +
            "left join sys_dict f on\n" +
            "\tc.type = f.code\n" +
            "\tAND f.type = 'mds_product_mx_type'" +
            "\twhere b.id =  #{processId} and c.id = #{procedureId}  ")
    TechnologyProcessProcedureNodeSimulate loadInfoByProcedure(@Param("processId") String processId,@Param("procedureId") String procedureId);

    @Select("select\n" +
            "\ta.*,\n" +
            "\tb.name process_name,\n" +
            "\td.name product_name,\n" +
            "\tc.name node_name,\n" +
            "\te.nick_name applicant,\n" +
            "\tf.name material_Name,\n" +
            "from\n" +
            "\tmds_technology_process_procedure_node_simulate a\n" +
            "left join mds_technology_process b on a.process_id = b.id\n" +
            "left join mds_technology_process_procedure_node c on a.process_id = c.process_id \n" +
            "left join mds_product d on b.product_id = d.id\n" +
            "left join sys_user e on a.created_by  = e.name\n" +
            "left join mds_material f on b.material_id  = f.id\n" +
            "where a.id = #{id}  ")
    MdsSimulateReport getReportById(@Param("id") String id);

    @Select("select\n" +
            "\ta.id id,\n" +
            "\ta.name name,\n" +
            "\tb.name process_name,\n" +
            "\tc.name procedure_name,\n" +
            "\tf.ext_str01 product_mx,\n" +
            "\ta.simulate_type simulate_type,\n" +
            "\ta.status status,\n" +
            "\td.name product_name\n" +
            "\tfrom\n" +
            "\tmds_technology_process_procedure_node_simulate a\n" +
            "\tleft join mds_technology_process b on a.process_id = b.id\n" +
            "\tleft join mds_technology_process_procedure c on a.process_id = c.process_id and a.procedure_id = c.id \n" +
            "\tleft join mds_product d on b.product_id = d.id\n" +
            "\tleft join sys_dict f on c.type = f.code AND f.type = 'mds_product_mx_type'\n" +
            "\twhere a.created_by = #{userId} order by  a.created_at desc  LIMIT 10  ")
    List<TechnologyProcessProcedureNodeSimulate> getHomeSimPageData(@Param("userId") String userId);
}
